#include<ros/ros.h>
#include<geometry_msgs/Twist.h>
#include<stdlib.h>
//向话题turtle1/cmd_vel随机发布消息，使海龟随机移动
int main(int argc , char** argv){
	//初始化
	ros::init(argc,argv,"publish_velocity");
	ros::NodeHandle nh;
	//发布者对象，一般一个话题对应一个对象
	ros::Publisher pub = nh.advertise<geometry_msgs::Twist>("turtle1/cmd_vel",1000);
	//初始化随机数种子
	srand(time(0));
	//控制频率
	ros::Rate rate(2);
	//节点是否停止工作，1.rosnode kill,2.Ctrl-C,3.ros::shutdown(),4.相同名字启动了其它节点
	while(ros::ok()){
		geometry_msgs::Twist msg;
		msg.linear.x = double(rand())/double(RAND_MAX);
		msg.angular.z= 2*double(rand())/double(RAND_MAX)-1;
		//发布消息
		pub.publish(msg);
		
		ROS_INFO_STREAM("Sending random velocity command:"<<"linear="<<msg.linear.x<<"angular"<<msg.angular.z);

		rate.sleep();
	}
	
}
